// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   StaffDaoImpl.java

package com.hfstu.pms.dataaccess.dao.impl;

import com.hfstu.framework.core.orm.Page;
import com.hfstu.framework.core.orm.PageRequest;
import com.hfstu.framework.core.orm.hibernate.PageDAOSpringTemplate;
import com.hfstu.framework.util.StringUtil;
import com.hfstu.pms.dataaccess.dao.IStaffDao;
import java.util.*;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.sql.JoinType;

public class StaffDaoImpl extends PageDAOSpringTemplate
	implements IStaffDao
{

	public StaffDaoImpl()
	{
	}

	private DetachedCriteria defaultCriteria()
	{
		DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass(), "staff");
		criteria.createAlias("staffDepartment", "sd", JoinType.LEFT_OUTER_JOIN);
		return criteria;
	}

	public Page findPageByCondition(PageRequest pageRequest, Map filterPropertyMap, Map sortValueMap)
	{
		DetachedCriteria criteria = defaultCriteria();
		org.hibernate.criterion.Criterion criterions[] = getCriterions(filterPropertyMap);
		org.hibernate.criterion.Criterion acriterion[];
		int j = (acriterion = criterions).length;
		for (int i = 0; i < j; i++)
		{
			org.hibernate.criterion.Criterion criterion = acriterion[i];
			criteria.add(criterion);
		}

		addOrderCriteria(criteria, sortValueMap);
		return super.findPageByCriteria(pageRequest, criteria);
	}

	public List findListByCondition(Map filterPropertyMap, Map sortValueMap)
	{
		StringBuilder hql = new StringBuilder();
		hql.append(" from Staff staff");
		StringBuilder whereHql = new StringBuilder();
		whereHql.append(" where 1=1");
		List values = new ArrayList();
		if (filterPropertyMap != null && !filterPropertyMap.isEmpty())
		{
			Object value = null;
			Set keys = filterPropertyMap.keySet();
			for (Iterator iterator = keys.iterator(); iterator.hasNext();)
			{
				String key = (String)iterator.next();
				value = filterPropertyMap.get(key);
				if (key.equals("staff.name") && !StringUtil.isNullOrEmpty((String)value))
				{
					whereHql.append(" and staff.name like ?");
					values.add((new StringBuilder("%")).append(StringUtil.clean((String)value)).append("%").toString());
				}
				value = null;
			}

		}
		hql.append(whereHql);
		if (sortValueMap != null && !sortValueMap.isEmpty())
		{
			StringBuilder orderbySql = new StringBuilder();
			Set keys = sortValueMap.keySet();
			for (Iterator iterator1 = keys.iterator(); iterator1.hasNext();)
			{
				String key = (String)iterator1.next();
				String value = (String)sortValueMap.get(key);
				if (!StringUtil.isNullOrEmpty(key) && !StringUtil.isNullOrEmpty(value))
				{
					if (orderbySql.length() == 0)
						orderbySql.append(" order by ");
					orderbySql.append(StringUtil.clean(key)).append(" ").append(StringUtil.clean(value)).append(",");
				}
			}

			if (orderbySql.length() > 0 && orderbySql.charAt(orderbySql.length() - 1) == ',')
				orderbySql.deleteCharAt(orderbySql.length() - 1);
			hql.append(orderbySql);
		}
		return super.findAllByHql(hql.toString(), values.toArray());
	}
}
